<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/


empty($do) && $do = 'list';
if ($do == 'edit') {
	$registration = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."registration where uid='".$_USER->id."' and date='".get_date('Y-m-d',PHP_TIME)."' ORDER BY id desc limit 0,1");
	if ($registration[enddate]!="")
	{
	$webenddate=$registration[enddate];
	$dateetype=1;
	}
	else
	{
	$webenddate=get_date('Y-m-d H:i:s',PHP_TIME);
	$dateetype=0;
	}
	
	include_once('template/edit.php');

} elseif ($do == 'save') {
	
	$savetype = getGP('savetype','P');
	$id = getGP('id','P','int');
	$enddate = getGP('enddate','P');
	$endnote = getGP('endnote','P');
	$h=GET_INC_CONFIG_INFO("ework")-getGP('starthour','P');
	$i=60-getGP('starthour1','P');
	if ($h>=0 && getGP('starthour','P')<GET_INC_CONFIG_INFO("ework")){
		$getstarthour = ($h-1).".".$i;
		$startyype="早退";
	}else{
		$getstarthour =0;
		$startyype="正常";
	}
	//echo $getstarthour;
	//exit;
	if ($id!=""){
	//主表信息
	$registration = array(
		'enddate' => $enddate,
		'endnote' => $endnote,
		'endtype' => $startyype,
		'endhour' => $getstarthour,
		'endip' => get_onlineip()
	);
	update_db('registration',$registration, array('id' => $id));
	$content=$_USER->name.get_inc_log(1).get_onlineip().get_inc_log(1).$enddate.get_inc_log(1).$endnote.get_inc_log(1).$startyype.get_inc_log(1).$getstarthour;
		$title='下班考勤登记';
		get_oa_log_dbadd($id,$content,$title,7,$_USER->id);
	}else
	{
	    
		$registration = array(
		'name' => $_USER->name,
		'uid' => $_USER->id,
		'date' => get_date('Y-m-d',PHP_TIME),
		'enddate' => $enddate,
		'endnote' => $endnote,
		'endtype' => $startyype,
		'endhour' => $getstarthour,
		'endip' => get_onlineip()
	);
		insert_db('registration',$registration);
		$id=$db->insert_id();
	    $content=$_USER->name.get_inc_log(1).get_onlineip().get_inc_log(1).$enddate.get_inc_log(1).$endnote.get_inc_log(1).$startyype.get_inc_log(1).$getstarthour;
		$title='下班考勤登记';
		get_oa_log_dbadd($id,$content,$title,7,$_USER->id);
	}
	goto_page('admin.php?ac=index&fileurl=registration');
	

}
?>